Chapter 2: Audio
Upload to S3
After getting the pre-signed url from aws, you need to upload the file to s3
- Use the provided pre-signed URL to upload the audio file directly to Amazon S3.
- The response of the
getPresignedAwsUrl
query must be parsed as follows:
let responseUrl = JSON.parse(
response.data.data.getPresignedAwsUrl.awsUrlObject
);
Example Curl Request
- Remember to replace the parameters in the example curl request
curl --location 'https://your-bucket-name.s3.amazonaws.com/' \
--form 'Content-Type="multipart/form-data"' \
--form 'key="UNIQUE_FILE_NAME"' \
--form 'x-amz-algorithm="AWS4-HMAC-SHA256"' \
--form 'x-amz-credential="COPY_FROM_GET_PRESIGNED_URL_RESPONSE"' \
--form 'x-amz-date="COPY_FROM_GET_PRESIGNED_URL_RESPONSE"' \
--form 'policy="COPY_FROM_GET_PRESIGNED_URL_RESPONSE"' \
--form 'x-amz-signature="COPY_FROM_GET_PRESIGNED_URL_RESPONSE"' \
--form 'file=@"<path-to-your-local-audio-file>.ogg"'
Example JS Implementation
- The fields can be obtained from the response of the
getPresignedAwsUrl
query.
import axios from "axios";
async function uploadAudioToAWS(url, File, fields, audioSlug) {
// Create a File object from the audio file
const file = new File([File], audioSlug, {
type: "video/ogg",
});
// Prepare FormData with AWS fields,
const formData = new FormData();
Object.keys(fields).forEach((key) => {
formData.append(key, fields[key]);
});
formData.append("file", file);
// Upload to S3
await axios
.post(url, formData, {
headers: {
"Content-Type": "multipart/form-data",
"x-api-key": process.env.VUE_APP_API_KEY,
},
})
.then((response) => {
console.log("File uploaded successfully: ", response.data);
})
.catch((error) => {
console.log("Error: ", error);
});
}
The URL is only valid for one file and has an expiration time of 5 minutes.
Have questions?
Still have questions? Talk to support.